<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <title>layui</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="../../lib/layui-v2.6.3/css/layui.css" media="all">
    <link rel="stylesheet" href="../../css/public.css" media="all">
    <style>
        body {
            background-color: #ffffff;
        }
    </style>
</head>

<body>
    <div class="layui-form layuimini-form" lay-filter="layuiform">
        <div class="layui-form-item">
            <label class="layui-form-label required">名称</label>
            <div class="layui-input-block">
                <input type="text" name="title" lay-verify="required" lay-reqtext="名称不能为空" placeholder="请输入名称" value=""
                    class="layui-input">

            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">图标</label>
            <div class="layui-input-block">
                <input name="icon" placeholder="请输入图标" value="" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">路径</label>
            <div class="layui-input-block">
                <input type="text" name="href" placeholder="请输入路径" value="" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item layui-form-text">
            <label class="layui-form-label">跳转方式</label>
            <div class="layui-input-block">
                <input name="target" class="layui-textarea" placeholder="跳转方式"></input>
            </div>
        </div>
        <div class="layui-form-item layui-form-text">
            <label class="layui-form-label">pid</label>
            <div class="layui-input-block">
                <input name="pid" class="layui-textarea" placeholder="pid"></input>
            </div>
        </div>

        <div class="layui-form-item">
            <div class="layui-input-block">
                <button class="layui-btn layui-btn-normal" lay-submit lay-filter="saveBtn">确认保存</button>
            </div>
        </div>
    </div>
    <script src="../../lib/layui-v2.6.3/layui.js" charset="utf-8"></script>
    <script src="../../js/t03.js"></script>
    <script>
        layui.use(['form'], function () {
            var form = layui.form,
                layer = layui.layer,
                $ = layui.$;

            //监听提交
            form.on('submit(saveBtn)', function (data) {
                var formData = form.val('layuiform'); // 获取表单数据 
           
        
            console.log(formData);
            
                $.ajax({
                    url: host + "/menu",
                    type: "POST",
                    data:JSON.stringify(formData),
                    contentType:"application/json",
                    success: function (data) {
                        console.log(data)
                        if (data === true) {
                            alert("操作成功");
                            // 在成功后关闭弹出层并刷新表格
                            var index = parent.layer.getFrameIndex(window.name); // 获取当前 iframe 的索引
                            parent.layer.close(index); // 关闭弹出层
                            // parent.table.reload('demo'); // 刷新表格
                            // parent.location.reload(); // 刷新父级页面
                        } else {
                            alert("操作失败，请重试！");
                        }
                    }
                });

                return false;
            });

        });
    </script>
</body>

</html>